package main

import (
	"flag"
	"fmt"
	"github.com/DangoXJ/secbinarycheck-result-analyzer/binscope"
	"github.com/DangoXJ/secbinarycheck-result-analyzer/common"
	"github.com/DangoXJ/secbinarycheck-result-analyzer/config"
	"github.com/DangoXJ/secbinarycheck-result-analyzer/vul"
	"os"
)

var (
	h bool
	c string
	b bool
	v bool
)

func init() {
	flag.StringVar(&c, "c", "conf/conf.yaml", "set configuration `file`")
	flag.BoolVar(&h, "h", false, "help")
	flag.BoolVar(&b, "b", false, "analyse binscope results")
	flag.BoolVar(&v, "v", false, "analyse vulnerabilities")

	flag.Parse()
	flag.Usage = usage
}

func usage() {
	_, _ = fmt.Fprintf(os.Stderr, `Usage: secbinarycheck-result-analyzer.exe [-hbv] [-c conf/conf.yaml]

Options:
`)
	flag.PrintDefaults()
}

func main() {

	if h || !b && !v {
		flag.Usage()
		os.Exit(0)
	}

	config.InitConf(c)
	config.InitBinScopeAnalysisBaseline(config.Conf.BinScope.BaselinePath)

	if b {
		b := binscope.NewBinScope()
		common.AnalyseFromDir(b, config.Conf.BinScope.InputPath, config.BinScopeAnalysisBaseline)
	}
	if v {
		v := vul.NewVul()
		common.AnalyseFromDir(v, config.Conf.BinScope.InputPath, config.BinScopeAnalysisBaseline)
	}

}
